package com.yuwei.parkinglot.adapter

import android.graphics.Color
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.tencent.smtt.utils.h
import com.yuwei.http.entity.ParkingLotEntityItem
import com.yuwei.parkinglot.R

class ParkingLotAdapter: BaseQuickAdapter<ParkingLotEntityItem, BaseViewHolder>(
    R.layout.parking_lot_item
) {

    override fun convert(holder: BaseViewHolder, item: ParkingLotEntityItem) {
        holder.setText(R.id.parking_lot_name,item.spaceNumber)
        holder.setText(R.id.parking_lot_area,item.areaName)
        holder.setText(R.id.parking_lot_type,item.spaceType)
        val userView = holder.getView<LinearLayout>(R.id.parking_lot_user_view)
        val carView = holder.getView<LinearLayout>(R.id.parking_lot_car_view)
        val repairView = holder.getView<LinearLayout>(R.id.parking_lot_repair_view)
        val status = holder.getView<TextView>(R.id.parking_lot_status)
        when(item.spaceStatus){
            "空闲"->{
                holder.setText(R.id.parking_lot_status,item.spaceStatus)
                status.setBackgroundResource(R.drawable.parking_lot_item_tv_bg1)
                status.setTextColor(Color.GREEN)
                userView.visibility = LinearLayout.GONE
                carView.visibility = LinearLayout.GONE
                repairView.visibility = LinearLayout.GONE
            }
            "已占用"->{
                holder.setText(R.id.parking_lot_status,item.spaceStatus)
                status.setBackgroundResource(R.drawable.parking_lot_item_tv_bg2)
                status.setTextColor(Color.BLUE)
                repairView.visibility = LinearLayout.GONE
            }
            "维护中"->{
                holder.setText(R.id.parking_lot_status,item.spaceStatus)
                status.setBackgroundResource(R.drawable.parking_lot_item_tv_bg3)
                status.setTextColor(Color.GRAY)
                userView.visibility = LinearLayout.GONE
                carView.visibility = LinearLayout.GONE
            }
            else->{
                holder.setText(R.id.parking_lot_status,"错误")
                status.setTextColor(Color.WHITE)
                status.setBackgroundResource(R.drawable.parking_lot_item_tv_bg4)
                userView.visibility = LinearLayout.GONE
                carView.visibility = LinearLayout.GONE
            }
        }
    }
}